<template>
<span class="op_dir-wrapper">
  <component v-if='components_name&&auths&&opBtns' :is='components_name' :auths='auths' :wrapper_name="wrapper_name" :btns="opBtns"></component>
</span>
</template>
<script>
    import tool from 'src/util/tool';
    import util from '_util/index';
    import logic from '_logic';
    import in_array from 'in_array';

    import Mbind from './Mbind.vue';
    import Model from './Model.vue';
    import Attr from './Attr.vue';
    import Export from './Export.vue';
    import cache_models from './cache_models.vue';
    import auth_tpl from './auth_tpl.vue';
    import myMenu from './Menu.vue';
    import Product from './Product.vue'
    import Taskcom from './Taskcom.vue'

	//提现列表
	import Withdraw from './Withdraw.vue';

    export default {
        data() {
            return {
                auths: null,
                opBtns: null,
            }
        },
        components: {
            Mbind, Attr, Model, Export, cache_models,auth_tpl,Product,myMenu,Withdraw,Taskcom
        },
        methods: {
            setAuth() {
                this.auths = util.modelFn('Auth', 'get_type_auth', this, 'op');
            },
            getopBtnsConf() {
                let opBtns = util.modelFn('Model', 'getopBtnsConf', this, this.ctl);
                if(!opBtns) {
                    this.opBtns = opBtns;
                    return;
                }
//                tool.cl('this.auths:', this.auths);
//                tool.cl('opBtns2:', opBtns);
                Object.keys(opBtns).forEach(field => {
                    if(!this.is_admin&&!this.auths.contains(field)) {
                        delete opBtns[field];
                    }
                });
//                tool.cl('opBtns3:', opBtns);
                this.opBtns = opBtns;
            }
        },
        computed: {
            wrapper_name(){
                return `op_${this.ctl}-wrapper`
            },
            ctl(){
                return this.$route.query.ctl;
            },
            is_admin(){
                return util.is_admin(this);
            },
            components_name() {
                let arr = ['Mbind', 'Model', 'Export', 'cache_models', 'auth_tpl', 'Menu','Product','Withdraw','Taskcom'];

                if (in_array(this.ctl, arr)){
                    let name = this.ctl;
                    switch (this.ctl) {
                        case 'Menu':
                            name='myMenu'

                    }
                    return name;
                }

                else
                    return null;
            }
        },
        watch: {
            _id: function (val, old) {
                if (val && val != old) {

                }
            },
            ctl: function (val, old) {
                if (val != old) {
                    this.setAuth();
                    this.getopBtnsConf();
                }
            }
        },

        props: ['btns'],
        created() {
            this.setAuth();
            this.getopBtnsConf();
        },
    }
</script>
<style rel="stylesheet/less" lang="less">@dir: "header/";</style>